<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script src="select2.js"></script>
<style type="text/css"> 
@import url("select2.css");
</style> 
</head>


<body ng-app="myApp"  ng-controller="myCtrl">

<select id="companyCode" class="form-control" style="width:400px" multiple="multiple">
<option value=""></option>
</select>


<script>

		var app = angular.module("myApp", []);
		app.controller("myCtrl", function($scope) {
		 

		$scope.names  = [{ id: 0, text: 'aaa' }, { id: "ZBXS", text: 'bbb' }, { id: 2, text: 'ccc' }];

            $scope.getSelectDataList = function () {
            };
            $scope.getSelectDataList();
            $scope.dataList=['11111','101920'];//赋值

		var list = [];
		$.each($scope.names, function (n, value) {
		 var obj = {id: value.id, text: value.text};
	   //     var obj = {id: value.clientCod, text: value.cClientNam};
			list.push(obj);
		});
		$("#companyCode").select2({
			data: list,
			placeholder: '请选择公司',
			allowClear:true
		});
		// 选择时触发事件并赋值
		$("#companyCode").on("select2:select", function (e) {
			var data = $(this).val();
			console.log(data);
		});
		$("#companyCode").select2("val", ["ZBXS"]);//赋值
		var res=$("#companyCode").select2("data")[0]; //取值
		console.log("res:"+res);
				
});


</script>
</body>
</html>
